package com.jixiang.goods.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jixiang.goods.dao.GsTypePicDao;
import com.jixiang.model.common.dtos.ResponseResult;
import com.jixiang.model.goods.dtos.GoodsTypePicDtos;
import com.jixiang.model.goods.entity.GsTypePic;
import com.jixiang.goods.service.GsTypePicService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * (GsTypePic)表服务实现类
 *
 * @author makejava
 * @since 2023-10-27 15:20:54
 */
@Service("gsTypePicService")
public class GsTypePicServiceImpl extends ServiceImpl<GsTypePicDao, GsTypePic> implements GsTypePicService {

    @Override
    public ResponseResult getGoodsTypePic(String id) {
        List<GsTypePic> list = query().eq("goods_type_id", id).orderByDesc("create_time").list();
        if(list == null || list.isEmpty()){
            return ResponseResult.okResult(null);
        }
        List<GoodsTypePicDtos> collect = list.stream().map(item -> {
            GoodsTypePicDtos goodsTypePicDtos = new GoodsTypePicDtos();
            goodsTypePicDtos.setUrl(item.getPic());
            int i = item.getPic().lastIndexOf("/");
            String substring = item.getPic().substring(i+1);
            goodsTypePicDtos.setName(substring);
            return goodsTypePicDtos;
        }).collect(Collectors.toList());
        return ResponseResult.okResult(collect);
    }
}

